home *** CD-ROM | disk | FTP | other *** search
/ Workplace Effectiveness: Critical Thinking Skills / Workplace Effectiveness: Critical Thinking Skills.iso / pc / Files / Puzzler.dxr / 00004_Puzzle parent.ls < prev    next >
Encoding:
Text File  |  1998-09-14  |  7.3 KB  |  170 lines

  1. property firstSprite, lastSprite, offsetNum, puzzleSprite, randomLocs, solveLocs, testRects, piecesMoved, piecesSolved, onesCount, tensCount, onesSprite, tensSprite, totalMoves
  2. global gSection, gMoverSprite
  3.  
  4. on new me
  5.   set the puzzleSprite of me to 3
  6.   set the onesSprite of me to 8
  7.   set the tensSprite of me to 9
  8.   set the firstSprite of me to 11
  9.   set the offsetNum of me to the firstSprite of me - 1
  10.   case gSection of
  11.     #puzzle1:
  12.       set the lastSprite of me to the firstSprite of me + 9
  13.     #puzzle2:
  14.       set the lastSprite of me to the firstSprite of me + 18
  15.     #puzzle3:
  16.       set the lastSprite of me to the firstSprite of me + 24
  17.   end case
  18.   case gSection of
  19.     #puzzle1:
  20.       set the piecesSolved of me to [11, 12, 14, 15, 16, 17, 18, 19, 20]
  21.     #puzzle2:
  22.       set the piecesSolved of me to [11, 12, 14, 15, 17, 18, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29]
  23.     #puzzle3:
  24.       set the piecesSolved of me to [11, 12, 14, 15, 17, 18, 20, 21, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35]
  25.   end case
  26.   setTargets(me)
  27.   return me
  28. end
  29.  
  30. on startPuzzle me
  31.   set the onesCount of me to 0
  32.   set the tensCount of me to 0
  33.   set the totalMoves of me to 0
  34.   setPuppetState([the onesSprite of me, the tensSprite of me], #c, 1)
  35.   setPuppetState([the firstSprite of me, the lastSprite of me], #c, 1)
  36.   puppetSprite(gMoverSprite, 1)
  37.   getSpriteLocs(me)
  38.   set the piecesMoved of me to []
  39.   sort(the piecesMoved of me)
  40. end
  41.  
  42. on clearPuzzle me
  43.   setPuppetState([the onesSprite of me, the tensSprite of me], #c, 0)
  44.   setPuppetState([the firstSprite of me, the lastSprite of me], #c, 0)
  45.   puppetSprite(gMoverSprite, 0)
  46. end
  47.  
  48. on getSpriteLocs me
  49.   set the randomLocs of me to [:]
  50.   repeat with snum = the firstSprite of me to the lastSprite of me
  51.     addProp(the randomLocs of me, snum, point(the locH of sprite snum, the locV of sprite snum))
  52.   end repeat
  53. end
  54.  
  55. on dragPiece me
  56.   startTimer()
  57.   set xsprite to the clickOn
  58.   set moveMember to the member of sprite xsprite
  59.   set offsetH to the locH of sprite xsprite - the mouseH
  60.   set offsetV to the locV of sprite xsprite - the mouseV
  61.   set the member of sprite gMoverSprite to moveMember
  62.   set the loc of sprite xsprite to point(-999, -999)
  63.   repeat while the mouseDown
  64.     if the timer > (60 * 4) then
  65.       PutBack(me, xsprite)
  66.       exit
  67.       next repeat
  68.     end if
  69.     set the loc of sprite gMoverSprite to point(the mouseH + offsetH, the mouseV + offsetV)
  70.     updateStage()
  71.   end repeat
  72.   EvalTarget(me, xsprite)
  73. end
  74.  
  75. on EvalTarget me, xsprite
  76.   set vlistPos to xsprite - the offsetNum of me
  77.   if inside(point(the mouseH, the mouseV), getAt(the testRects of me, vlistPos)) then
  78.     setItDown(me, xsprite, vlistPos)
  79.   else
  80.     if rollOver(the puzzleSprite of me) then
  81.       PutBack(me, xsprite)
  82.     else
  83.       if inside(the loc of sprite gMoverSprite, the rect of sprite 1) then
  84.         LetGo(me, xsprite)
  85.       else
  86.         PutBack(me, xsprite)
  87.       end if
  88.     end if
  89.   end if
  90. end
  91.  
  92. on setItDown me, xsprite, vlistPos
  93.   puppetSound("thingset")
  94.   set the loc of sprite xsprite to getAt(the solveLocs of me, vlistPos)
  95.   set the loc of sprite gMoverSprite to point(-999, -999)
  96.   if getPos(the piecesMoved of me, xsprite) = 0 then
  97.     add(the piecesMoved of me, xsprite)
  98.   end if
  99.   addToCounter(me)
  100.   updateStage()
  101.   checkifSolved(me)
  102. end
  103.  
  104. on PutBack me, xsprite
  105.   puppetSound("swoosh")
  106.   set vOrigLoc to getaProp(the randomLocs of me, xsprite)
  107.   set the loc of sprite xsprite to vOrigLoc
  108.   set the loc of sprite gMoverSprite to point(-999, -999)
  109.   set listPos to getPos(the piecesMoved of me, xsprite)
  110.   if listPos <> 0 then
  111.     deleteAt(the piecesMoved of me, listPos)
  112.   end if
  113.   addToCounter(me)
  114.   updateStage()
  115. end
  116.  
  117. on LetGo me, xsprite
  118.   set offsetH to the locH of sprite gMoverSprite - the mouseH
  119.   set offsetV to the locV of sprite gMoverSprite - the mouseV
  120.   set vNewPoint to point(the mouseH + offsetH, the mouseV + offsetV)
  121.   setProp(the randomLocs of me, xsprite, vNewPoint)
  122.   set the loc of sprite xsprite to vNewPoint
  123.   set the loc of sprite gMoverSprite to point(-999, -999)
  124.   updateStage()
  125. end
  126.  
  127. on addToCounter me
  128.   if the onesCount of me = 9 then
  129.     set the onesCount of me to 0
  130.     if the tensCount of me = 9 then
  131.       set the tensCount of me to 0
  132.     else
  133.       set the tensCount of me to the tensCount of me + 1
  134.     end if
  135.   else
  136.     set the onesCount of me to the onesCount of me + 1
  137.   end if
  138.   set the totalMoves of me to the totalMoves of me + 1
  139.   showCounter(me)
  140. end
  141.  
  142. on showCounter me
  143.   set the member of sprite the onesSprite of me to member ("digit" & string(the onesCount of me))
  144.   set the member of sprite the tensSprite of me to member ("digit" & string(the tensCount of me))
  145. end
  146.  
  147. on checkifSolved me
  148.   if the piecesMoved of me = the piecesSolved of me then
  149.     puppetSound("Cheering")
  150.   end if
  151. end
  152.  
  153. on getTotalMoves me
  154.   return string(the totalMoves of me)
  155. end
  156.  
  157. on setTargets me
  158.   case gSection of
  159.     #puzzle1:
  160.       set the solveLocs of me to [point(211, 143), point(340, 143), point(-100, -100), point(448, 127), point(191, 242), point(320, 240), point(448, 227), point(212, 321), point(320, 322), point(428, 322)]
  161.       set the testRects of me to [rect(128, 78, 295, 208), rect(253, 78, 427, 208), rect(-100, -100, -90, -90), rect(385, 78, 512, 176), rect(128, 175, 255, 309), rect(214, 175, 432, 311), rect(385, 143, 512, 311), rect(128, 277, 297, 366), rect(255, 279, 385, 366), rect(344, 279, 512, 366)]
  162.     #puzzle2:
  163.       set the solveLocs of me to [point(176, 124), point(273, 113), point(-100, -100), point(387, 124), point(467, 125), point(-100, -100), point(191, 197), point(289, 184), point(-100, -100), point(371, 185), point(450, 197), point(176, 273), point(273, 273), point(386, 262), point(466, 273), point(191, 332), point(273, 332), point(371, 331), point(466, 333)]
  164.       set the testRects of me to [rect(128, 78, 225, 171), rect(194, 78, 353, 148), rect(-100, -100, -90, -90), rect(323, 78, 452, 171), rect(422, 78, 512, 172), rect(-100, -100, -90, -90), rect(128, 147, 255, 247), rect(223, 121, 355, 247), rect(-100, -100, -90, -90), rect(322, 147, 421, 224), rect(389, 146, 512, 248), rect(128, 223, 224, 324), rect(194, 223, 352, 324), rect(323, 200, 449, 325), rect(420, 222, 512, 325), rect(128, 299, 255, 366), rect(224, 299, 323, 366), rect(292, 297, 451, 366), rect(420, 300, 512, 366)]
  165.     #puzzle3:
  166.       set the solveLocs of me to [point(168, 124), point(245, 113), point(-100, -100), point(338, 124), point(418, 124), point(-100, -100), point(477, 124), point(179, 197), point(-100, -100), point(258, 185), point(325, 185), point(-100, -100), point(404, 197), point(477, 185), point(-100, -100), point(167, 273), point(245, 273), point(340, 262), point(416, 273), point(477, 261), point(179, 332), point(246, 333), point(325, 332), point(404, 333), point(465, 332)]
  167.       set the testRects of me to [rect(128, 78, 208, 171), rect(181, 78, 310, 148), rect(-100, -100, -90, -90), rect(286, 78, 391, 171), rect(365, 78, 471, 171), rect(-100, -100, -90, -90), rect(443, 78, 512, 171), rect(128, 147, 231, 247), rect(-100, -100, -90, -90), rect(204, 123, 312, 247), rect(285, 146, 365, 224), rect(-100, -100, -90, -90), rect(340, 147, 469, 248), rect(443, 147, 512, 223), rect(-100, -100, -90, -90), rect(128, 223, 206, 324), rect(181, 222, 310, 324), rect(286, 200, 395, 325), rect(365, 222, 468, 324), rect(443, 199, 512, 324), rect(128, 299, 231, 366), rect(206, 300, 286, 366), rect(261, 299, 390, 366), rect(365, 300, 444, 366), rect(419, 299, 512, 366)]
  168.   end case
  169. end
  170.